package cn.kgc.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 课工场
 * @since 2023/9/2
 */
@RestController
@RequestMapping("hystrix")
public class HystrixController {

    @GetMapping("m1")
    @HystrixCommand(fallbackMethod = "method1Fallback")
    public String method1(Integer id){
        if (id<0){
            throw  new RuntimeException("参数异常！请重试");
        }
        return "HystrixController ok";
    }

    // 快速响应方法  返回值  和 参数列表和 method1保持一致
    public String method1Fallback(Integer id){
        System.out.println("============id =-=============== " + id);
        return "参数异常！请重试";
    }

}
